import { Injectable } from "@nestjs/common";
import { MongoService } from "./mongo.service";

@Injectable()
export class MsgService {
    constructor(
        private mongoService : MongoService
    ){
        
    }

    getConversationIdByMsg(msg:any)
    {
        let other = null
        
        if (msg.Data.FromUserName.string == msg.Wxid) {
            other = msg.Data.ToUserName.string
        }else{
            other =  msg.Data.FromUserName.string
        }

        return other
    }

    async generateMessage(){
        let chatrooms =  [
            {
                "userName": "49224174425@chatroom",
                "nickName": "掌聘-资料记录群",
                "pyInitial": "ZPZLJLQ",
                "quanPin": "zhangpinziliaojiluqun",
                "sex": 0,
                "remark": null,
                "remarkPyInitial": null,
                "remarkQuanPin": null,
                "signature": null,
                "alias": null,
                "snsBgImg": null,
                "country": null,
                "bigHeadImgUrl": null,
                "smallHeadImgUrl": "http://wx.qlogo.cn/mmcrhead/Tdq4ZiasI5w1lMAia1HhYYlapiaYnQDDWhjWernUCpSEg2OmXD70fX5lDUu6dHmKAtR0EpGdlZprNs/0",
                "description": null,
                "cardImgUrl": null,
                "labelList": null,
                "province": null,
                "city": null,
                "phoneNumList": null
            },
            {
                "userName": "22221969224@chatroom",
                "nickName": "桔东联防联控群",
                "pyInitial": "JDLFLKQ",
                "quanPin": "jiedonglianfangliankongqun",
                "sex": 0,
                "remark": null,
                "remarkPyInitial": null,
                "remarkQuanPin": null,
                "signature": null,
                "alias": null,
                "snsBgImg": null,
                "country": null,
                "bigHeadImgUrl": null,
                "smallHeadImgUrl": "http://wx.qlogo.cn/mmcrhead/XVl394F2tkQSoYtpW8FI1WBlDNGaJnGxaqFnOxoicKAfSeuYpokrG1uIGm3aOcOjOq8OfRNPECUo/0",
                "description": null,
                "cardImgUrl": null,
                "labelList": null,
                "province": null,
                "city": null,
                "phoneNumList": null
            },
            {
                "userName": "48110778947@chatroom",
                "nickName": "【掌聘】外单入库群",
                "pyInitial": "ZPWDRKQ",
                "quanPin": "zhangpinwaidanrukuqun",
                "sex": 0,
                "remark": null,
                "remarkPyInitial": null,
                "remarkQuanPin": null,
                "signature": null,
                "alias": null,
                "snsBgImg": null,
                "country": null,
                "bigHeadImgUrl": null,
                "smallHeadImgUrl": "http://wx.qlogo.cn/mmcrhead/hZNWx4sy4ic50e0wIrbeR8sVrrJzxNxvXibSUmoxYYiavhkNWVNUhoKM0w9WibC5ux5lLkhXmVibBIQw/0",
                "description": null,
                "cardImgUrl": null,
                "labelList": null,
                "province": null,
                "city": null,
                "phoneNumList": null
            },
            {
                "userName": "45301600875@chatroom",
                "nickName": "掌聘-掌聘备忘群",
                "pyInitial": "ZPZPBWQ",
                "quanPin": "zhangpinzhangpinbeiwangqun",
                "sex": 0,
                "remark": null,
                "remarkPyInitial": null,
                "remarkQuanPin": null,
                "signature": null,
                "alias": null,
                "snsBgImg": null,
                "country": null,
                "bigHeadImgUrl": null,
                "smallHeadImgUrl": "http://wx.qlogo.cn/mmcrhead/sS0bcEW5pxujMabyUOmo0QxSfy7R8Of2LGic13vZriagg6LsWIOXnicFrJox6q9RQx8clk4AcTFiaGM/0",
                "description": null,
                "cardImgUrl": null,
                "labelList": null,
                "province": null,
                "city": null,
                "phoneNumList": null
            },
            {
                "userName": "48519374776@chatroom",
                "nickName": "掌聘-发布渠道收集群",
                "pyInitial": "ZPFBQDSJQ",
                "quanPin": "zhangpinfabuqudaoshoujiqun",
                "sex": 0,
                "remark": null,
                "remarkPyInitial": null,
                "remarkQuanPin": null,
                "signature": null,
                "alias": null,
                "snsBgImg": null,
                "country": null,
                "bigHeadImgUrl": null,
                "smallHeadImgUrl": "http://wx.qlogo.cn/mmcrhead/XmGbkpeeGkoDQ412J0t25ibateIIwZ9TuqWpjoV3hvBlTuzjxnclgqYMsP9RJtcDRBXhv8jsQHSg/0",
                "description": null,
                "cardImgUrl": null,
                "labelList": null,
                "province": null,
                "city": null,
                "phoneNumList": null
            },
            {
                "userName": "48109774883@chatroom",
                "nickName": "掌聘-接单渠道收集群",
                "pyInitial": "ZPJDQDSJQ",
                "quanPin": "zhangpinjiedanqudaoshoujiqun",
                "sex": 0,
                "remark": null,
                "remarkPyInitial": null,
                "remarkQuanPin": null,
                "signature": null,
                "alias": null,
                "snsBgImg": null,
                "country": null,
                "bigHeadImgUrl": null,
                "smallHeadImgUrl": "http://wx.qlogo.cn/mmcrhead/TbNxhb3icdSiaA16YwTS3eycjTjf8RuD1CdMfZVhOiaYYLiciaojB5bryrkIDvhZJetpB1AAI2bLNyicY/0",
                "description": null,
                "cardImgUrl": null,
                "labelList": null,
                "province": null,
                "city": null,
                "phoneNumList": null
            },
            {
                "userName": "34662294323@chatroom",
                "nickName": "【公司群】掌聘人力",
                "pyInitial": "GSQZPRL",
                "quanPin": "gongsiqunzhangpinrenli",
                "sex": 0,
                "remark": null,
                "remarkPyInitial": null,
                "remarkQuanPin": null,
                "signature": null,
                "alias": null,
                "snsBgImg": null,
                "country": null,
                "bigHeadImgUrl": null,
                "smallHeadImgUrl": "http://wx.qlogo.cn/mmcrhead/31VrSwMkXTnIbBQxejxOuywxtlBZSXucLibtD0BVA6BnCb6f51N79Pnf71Tibz23dBVDbkiahU8gIU/0",
                "description": null,
                "cardImgUrl": null,
                "labelList": null,
                "province": null,
                "city": null,
                "phoneNumList": null
            },
            {
                "userName": "44363011655@chatroom",
                "nickName": "【掌聘】实时招聘信息群",
                "pyInitial": "ZPSSZPXXQ",
                "quanPin": "zhangpinshishizhaopinxinxiqun",
                "sex": 0,
                "remark": null,
                "remarkPyInitial": null,
                "remarkQuanPin": null,
                "signature": null,
                "alias": null,
                "snsBgImg": null,
                "country": null,
                "bigHeadImgUrl": null,
                "smallHeadImgUrl": "http://wx.qlogo.cn/mmcrhead/EA2yLhZ5nLBDE8pQxTbW3fv3X6dBnEbo8Mhh5xEBK2GxmibzdbAfWbTCKT3HrHdSm0BGsjfPoKxE/0",
                "description": null,
                "cardImgUrl": null,
                "labelList": null,
                "province": null,
                "city": null,
                "phoneNumList": null
            },
            {
                "userName": "50165056244@chatroom",
                "nickName": "掌聘-项目状态沟通群",
                "pyInitial": "ZPXMZTGTQ",
                "quanPin": "zhangpinxiangmuzhuangtaigoutongqun",
                "sex": 0,
                "remark": null,
                "remarkPyInitial": null,
                "remarkQuanPin": null,
                "signature": null,
                "alias": null,
                "snsBgImg": null,
                "country": null,
                "bigHeadImgUrl": null,
                "smallHeadImgUrl": "http://wx.qlogo.cn/mmcrhead/eibRxncsk8eYcmqyOD1hWricAMKzdLqCX5WWr5GZqdicLuPqpCKEIkfJuwL1AlEqfZTISSMHrU86hk/0",
                "description": null,
                "cardImgUrl": null,
                "labelList": null,
                "province": null,
                "city": null,
                "phoneNumList": null
            }
        ]

        let msg = {
            "TypeName": "AddMsg",    //消息类型
            "Appid": "wx_5l-eC0uimXCDlLMNB99SM",  //设备ID
            "Wxid": "beckham996",  //所属微信的wxid
            "Data":
            {
                "MsgSeq": 0,
                "MsgId": 0,   //消息ID
                "FromUserName":
                {
                    "string": "wxid_phyyedw9xap22"  //消息发送人的wxid
                },
                "ToUserName":
                {
                    "string":  chatrooms[Math.floor(Math.random() * chatrooms.length)].userName //"wxid_0xsqb3o0tsvz22"  //消息接收人的wxid
                },
                "MsgType": 1,   //消息类型 1是文本消息
                "Content":
                {
                    "string": "123" //# 消息内容
                },
                "Status": 3,
                "ImgStatus": 1,
                "ImgBuf":
                {
                    "iLen": 0
                },
                "CreateTime": 1705043418,  //消息发送时间
                "MsgSource": "<msgsource>\n\t<alnode>\n\t\t<fr>1</fr>\n\t</alnode>\n\t<signature>v1_volHXhv4</signature>\n\t<tmp_node>\n\t\t<publisher-id></publisher-id>\n\t</tmp_node>\n</msgsource>\n",
                "PushContent": "朝夕。 : 123",  //消息通知内容 
                "NewMsgId": 0,  //消息ID
            }
        }

        return msg
    }
}